/**
 * @Description: 静态内部类实现单例模式
 * @Author: WangBlue
 * @Create: 2024-09-23 16:10
 * @Version: 1.0
 **/

public class StaticInternal {
    // 私有化构造方法
    private StaticInternal() { }

    private static class SingletonHolder {
        private static final StaticInternal INSTANCE = new StaticInternal();
    }

    //对外提供静态方法获取该对象
    public static StaticInternal getInstance() {
        return SingletonHolder.INSTANCE;
    }
}


class Test {
    public static void main(String[] args) {
        StaticInternal instance1 = StaticInternal.getInstance();
        StaticInternal instance2 = StaticInternal.getInstance();
        if (instance1 == instance2) {
            System.out.println("这两个是同一个实例对象");
        }
    }
}